<?php

namespace App\Http\Controllers\Admin\Wechat;

use App\Models\Shop\Customer;
use App\Models\Wechat\Prize;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PrizeController extends Controller
{
    public function __construct()
    {
        view()->share([
            '_wechat' => 'am-in',
            '_prize' => 'am-active'
        ]);
    }

    public function index(Request $request)
    {
        //模糊查询
        $where = function ($query) use ($request) {
            if ($request->has('keyword') and $request->keyword != '') {
                $search = "%" . $request->keyword . "%";
                $customer_id = Customer::where('nickname', 'like', $search)->pluck('id');
                $query->whereIn('customer_id', $customer_id);
            }
        };

        $prizes = Prize::where($where)->with('draw', 'customers')->paginate(5);
//        return $prizes;
        return view('admin.wechat.prize.index', compact('prizes'));
    }

    public function delete(Request $request)
    {
        Prize::destroy($request->id);
    }


}
